package com.jd.financeweb.controller;

import com.jd.financeweb.service.LoadService;
import com.jd.financeweb.service.impl.LoadServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @ClassName RepayController
 * @Description TODO
 * @Author LiQingBo
 * @Date 2022/5/22 21:02
 */
@WebServlet("/getRepayProd")
public class RepayController extends HttpServlet {

    LoadService loadService = new LoadServiceImpl();

    /**
     * 根据uid查询代还款产品
     *
     * @param req 用户身份证号或企业编号
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //用户身份证号
        String idNo = req.getParameter("idNo");
        //企业编号
        String cpNo = req.getParameter("cpNo");
        String response;
        if (idNo==null){
            response = loadService.companyRepayProd(cpNo);
        }else {
            response = loadService.userRepayProd(idNo);
        }
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        out.println(response);
        out.flush();
        out.close();

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
